package cc.taofoo.NIO;

import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class CHANNEL {
    public static void main(String[] args) throws Exception {
        RandomAccessFile file = new RandomAccessFile("D:/youngstudy.py","rw");
        FileChannel fc = file.getChannel();

        ByteBuffer buf = ByteBuffer.allocate(48);

        int byteRead = fc.read(buf);
        while (byteRead != -1){
            buf.flip();
            while (buf.hasRemaining()){
                System.out.print((char)buf.get());
            }
            buf.clear();
            byteRead= fc.read(buf);
        }
        file.close();
    }
}
